package cn.wolfcode.luowowo.packagetour.template;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Document(indexName="luowowo_packagetour",type="packagetour")
@Getter
@Setter
public class PackageTourTemplate implements Serializable {
    public static final String INDEX_NAME = "luowowo_packagetour";
    public static final String TYPE_NAME = "packagetour";
    @Id
    //@Field 每个文档的字段配置（类型、是否分词、是否存储、分词器 ）
    @Field(store=true, index = false,type = FieldType.Long)
    private Long id;

    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer travelWay;      //旅游方式
    @Field(index=true,store=true,type = FieldType.Keyword)
    private String coverUrl;        //封面
    @Field(store=true, index = true,type = FieldType.Long)
    private Long startPlace_id;     //出发地点
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String startPlaceName;



    @Field(store=true, index = true,type = FieldType.Long)
    private Long dest_id;           //目的地
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String destName;

    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer saleNum;        //已售数
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String title;           //标题
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String subTitle;        //副标题
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String tags;            //标签
    @Field(pattern = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis", type=FieldType.Date, format = DateFormat.custom)
    private Date startTime;         //班期开始时间
    @Field(pattern = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis", type=FieldType.Date, format = DateFormat.custom)
    private Date endTime;           //班期结束时间
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer minPrice;       //最低价格
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer maxPrice;       //最高价格
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer feature;        //产品特色
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer days;           //旅游天数
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer shop_id;        //商铺id
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String shopName;        //商铺名称

    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer isPromotion;    //是否促销
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer isBigPromotion; //是否大促
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String promotionContent;//促销信息
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer coupon;         //是否有券
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer vipCoupon;      //是否有vip券
    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer hotel_id;       //酒店id
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String hotelName;       //酒店名称

    @Field(store=true, index = true,type = FieldType.Integer)
    private Integer favorNum;       //收藏数
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String moreService;     //更多服务标题
    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String moreServiceInfo; //更多服务信息
    @Field(store=true, index = true,type = FieldType.Long)
    private Long combo_id;          //套餐id

    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String url;             //信息链接

    @Field(index=true,analyzer="ik_max_word",store=true,searchAnalyzer="ik_max_word",type = FieldType.Text)
    private String images;          //图片库

    public String getTravelWayName(){
        String str = "境内跟团游";
        if(travelWay == null){
            return str;
        }
        if(travelWay == 2){
            str = "境内半自助游";
        }else if(travelWay == 3){
            str = "私家团";
        }else if(travelWay == 4){
            str = "出境跟团游";
        }else if(travelWay == 5){
            str = "游学团";
        }else if(travelWay == 6){
            str = "出境半自助游";
        }
        return str;
    }

    public List<String> getTagName(){
        ArrayList<String> list = new ArrayList<>();
        if (tags != null && tags.length()>0){
            String[] strs = tags.split(",");
            for (String str : strs) {
                list.add(str);
            }
        }
        return list;
    }

    public List<String> getImgs(){
        ArrayList<String> list = new ArrayList<>();
        if (images != null && images.length()>0){
            String[] strs = images.split(",");
            for (String s : strs) {
                list.add(s);
            }
        }
        return list;
    }

}
